package com.cryann.mqttserver.mqttProcess;

import com.cryann.mqttserver.service.MqttSubject;
import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author cRyann
 * @date 2018/12/25 0025 15:20
 * @description:
 */
@Component
@Slf4j
@ProcessType(MqttMessageType.PUBREC)
public class Pubrec implements BasicProcess<MqttMessage> {

    @Autowired
    MqttSubject mqttSubject;

    @Override
    public void process(Channel ctx, MqttMessage mqttMessage) {
        MqttMessage msg = MqttMessageFactory.newMessage(
                new MqttFixedHeader(MqttMessageType.PUBREL, false, mqttMessage.fixedHeader().qosLevel(), false, 2),
                MqttMessageIdVariableHeader.from(((MqttMessageIdVariableHeader) mqttMessage.variableHeader()).messageId()),
                null
        );
        ctx.writeAndFlush(msg);
    }
}
